package com.yanqu.road.server.cmd.cookboy.process3;

import com.yanqu.road.pb.cookboy.CookBoyProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.cookboy.CrossCookBoyMgr;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;


@Cmd(code = Protocol.C_CROSS_COOK_BOY3_JOIN_BANQUET, desc = "参加宴会")
public class CrossJoinBanquetCmd extends CrossCommand {

    private int activityId;
    private long joinUserId;
    private long homeUserId;
    private int banquetId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        CookBoyProto.CookBoy3JoinBanquetReqMsg reqMsg = CookBoyProto.CookBoy3JoinBanquetReqMsg.parseFrom(packet.getBytes());
        joinUserId = packet.getPlayerId();
        homeUserId = reqMsg.getUserId();
        activityId = reqMsg.getActivityId();
        banquetId = reqMsg.getBanquetId();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        ret = CrossCookBoyMgr.joinBanquet(activityId,serverId,joinUserId,homeUserId,banquetId);
    }

    @Override
    public void sendData() {
        if(ret != 0){
            CookBoyProto.CookBoy3JoinBanquetRespMsg.Builder msg = CookBoyProto.CookBoy3JoinBanquetRespMsg.newBuilder();
            msg.setRet(ret);
            YanQuMessage pbMsg = YanQuMessageUtils.buildMessage(Protocol.U_COOK_BOY3_JOIN_BANQUET, msg);
            MessageHelper.sendPacket(serverId, joinUserId, pbMsg);
        }
    }

}
